using Godot;

namespace MyCraft2;

public partial class WindowControl : Node
{
    public const string ClearScreen = "clear_screen";
    public const string FullScreen = "full_screen";

    private DisplayServer.WindowMode _previousWindowState = DisplayServer.WindowMode.Windowed;

    [Export] public Control? Control;
    
    public override void _Ready()
    {
        base._Ready();

        InputMapExtend.AddAction(ClearScreen, new InputEventKey { Keycode = Key.F1 });
        InputMapExtend.AddAction(FullScreen, new InputEventKey { Keycode = Key.F11 });
    }

    public override void _Input(InputEvent @event)
    {
        base._Input(@event);

        if (Input.IsActionJustPressed(FullScreen))
        {
            var windowMode = DisplayServer.WindowGetMode();
            DisplayServer.WindowSetMode(windowMode is DisplayServer.WindowMode.Fullscreen
                ? _previousWindowState
                : DisplayServer.WindowMode.Fullscreen);
        }

        if (Input.IsActionJustPressed(ClearScreen) && Control is not null)
            Control.Visible = !Control.Visible;
    }
}
